#!/usr/bin/env bash
#########################################################################
# File Name   : create_network.sh
# Author      : seadog
# mail        : seadog0514@163.com
# Version     : 0.1
# Created Time: Thu 2024-10-03 14:17:20(+0800)
#########################################################################

#
#
# Usage:

{
  set -euo pipefail

  export TZ="Asia/Shanghai"
  APP_ROOT=$(dirname "$(readlink -fm "$0")")
  cd "${APP_ROOT}"

  exec &> >(tee -a "/tmp/gw_chassis.log")

}

# !!! setup router 'r1' gateway_chassis
sleep 3
ovn-sbctl show
gw_chassis_id=$(ovn-sbctl show | sed -n '/hostname: {{ openstack_neutron_hostname }}/{g;1!p;};h' | cut -d'"' -f2)
external_connection_port=$(ovn-nbctl list Logical_Router_Port | sed -n '/192.168.5/{g;1!p;};h' | gawk '{print $3}')
ovn-nbctl lrp-set-gateway-chassis "${external_connection_port}" "${gw_chassis_id}"
ovn-nbctl list gateway_chassis
ovn-nbctl show r1
